﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace Taxes.DAL
{
	/// <summary>
	/// 数据访问类:levy_record
	/// </summary>
	public partial class levy_record
	{
		public levy_record()
		{}
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperSQL.GetMaxID("lr_id", "levy_record"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int lr_id)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from levy_record");
			strSql.Append(" where lr_id=@lr_id");
			SqlParameter[] parameters = {
					new SqlParameter("@lr_id", SqlDbType.Int,4)
};
			parameters[0].Value = lr_id;

			return DbHelperSQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(Taxes.Model.levy_record model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into levy_record(");
			strSql.Append("lr_code,lr_ny,lr_yys,lr_cjs,lr_zys,lr_fcs,lr_tdsys,lr_tdzzs,lr_yhs,lr_ccs,lr_qysds,lr_grsds,lr_jyffj,lr_dfjyffj,lr_sljszxzj,lr_whsyjsf,lr_jbylbx,lr_gsbx,ls_ngsybx,ls_jbylbx,ls_sybx,ls_cjrbzj)");
			strSql.Append(" values (");
			strSql.Append("@lr_code,@lr_ny,@lr_yys,@lr_cjs,@lr_zys,@lr_fcs,@lr_tdsys,@lr_tdzzs,@lr_yhs,@lr_ccs,@lr_qysds,@lr_grsds,@lr_jyffj,@lr_dfjyffj,@lr_sljszxzj,@lr_whsyjsf,@lr_jbylbx,@lr_gsbx,@ls_ngsybx,@ls_jbylbx,@ls_sybx,@ls_cjrbzj)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("@lr_code", SqlDbType.Char,9),
					new SqlParameter("@lr_ny", SqlDbType.Char,6),
					new SqlParameter("@lr_yys", SqlDbType.Decimal,9),
					new SqlParameter("@lr_cjs", SqlDbType.Decimal,9),
					new SqlParameter("@lr_zys", SqlDbType.Decimal,9),
					new SqlParameter("@lr_fcs", SqlDbType.Decimal,9),
					new SqlParameter("@lr_tdsys", SqlDbType.Decimal,9),
					new SqlParameter("@lr_tdzzs", SqlDbType.Decimal,9),
					new SqlParameter("@lr_yhs", SqlDbType.Decimal,9),
					new SqlParameter("@lr_ccs", SqlDbType.Decimal,9),
					new SqlParameter("@lr_qysds", SqlDbType.Decimal,9),
					new SqlParameter("@lr_grsds", SqlDbType.Decimal,9),
					new SqlParameter("@lr_jyffj", SqlDbType.Decimal,9),
					new SqlParameter("@lr_dfjyffj", SqlDbType.Decimal,9),
					new SqlParameter("@lr_sljszxzj", SqlDbType.Decimal,9),
					new SqlParameter("@lr_whsyjsf", SqlDbType.Decimal,9),
					new SqlParameter("@lr_jbylbx", SqlDbType.Decimal,9),
					new SqlParameter("@lr_gsbx", SqlDbType.Decimal,9),
					new SqlParameter("@ls_ngsybx", SqlDbType.Decimal,9),
					new SqlParameter("@ls_jbylbx", SqlDbType.Decimal,9),
					new SqlParameter("@ls_sybx", SqlDbType.Decimal,9),
					new SqlParameter("@ls_cjrbzj", SqlDbType.Decimal,9)};
			parameters[0].Value = model.lr_code;
			parameters[1].Value = model.lr_ny;
			parameters[2].Value = model.lr_yys;
			parameters[3].Value = model.lr_cjs;
			parameters[4].Value = model.lr_zys;
			parameters[5].Value = model.lr_fcs;
			parameters[6].Value = model.lr_tdsys;
			parameters[7].Value = model.lr_tdzzs;
			parameters[8].Value = model.lr_yhs;
			parameters[9].Value = model.lr_ccs;
			parameters[10].Value = model.lr_qysds;
			parameters[11].Value = model.lr_grsds;
			parameters[12].Value = model.lr_jyffj;
			parameters[13].Value = model.lr_dfjyffj;
			parameters[14].Value = model.lr_sljszxzj;
			parameters[15].Value = model.lr_whsyjsf;
			parameters[16].Value = model.lr_jbylbx;
			parameters[17].Value = model.lr_gsbx;
			parameters[18].Value = model.ls_ngsybx;
			parameters[19].Value = model.ls_jbylbx;
			parameters[20].Value = model.ls_sybx;
			parameters[21].Value = model.ls_cjrbzj;

			object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters);
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Taxes.Model.levy_record model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update levy_record set ");
			strSql.Append("lr_code=@lr_code,");
			strSql.Append("lr_ny=@lr_ny,");
			strSql.Append("lr_yys=@lr_yys,");
			strSql.Append("lr_cjs=@lr_cjs,");
			strSql.Append("lr_zys=@lr_zys,");
			strSql.Append("lr_fcs=@lr_fcs,");
			strSql.Append("lr_tdsys=@lr_tdsys,");
			strSql.Append("lr_tdzzs=@lr_tdzzs,");
			strSql.Append("lr_yhs=@lr_yhs,");
			strSql.Append("lr_ccs=@lr_ccs,");
			strSql.Append("lr_qysds=@lr_qysds,");
			strSql.Append("lr_grsds=@lr_grsds,");
			strSql.Append("lr_jyffj=@lr_jyffj,");
			strSql.Append("lr_dfjyffj=@lr_dfjyffj,");
			strSql.Append("lr_sljszxzj=@lr_sljszxzj,");
			strSql.Append("lr_whsyjsf=@lr_whsyjsf,");
			strSql.Append("lr_jbylbx=@lr_jbylbx,");
			strSql.Append("lr_gsbx=@lr_gsbx,");
			strSql.Append("ls_ngsybx=@ls_ngsybx,");
			strSql.Append("ls_jbylbx=@ls_jbylbx,");
			strSql.Append("ls_sybx=@ls_sybx,");
			strSql.Append("ls_cjrbzj=@ls_cjrbzj");
			strSql.Append(" where lr_id=@lr_id");
			SqlParameter[] parameters = {
					new SqlParameter("@lr_code", SqlDbType.Char,9),
					new SqlParameter("@lr_ny", SqlDbType.Char,6),
					new SqlParameter("@lr_yys", SqlDbType.Decimal,9),
					new SqlParameter("@lr_cjs", SqlDbType.Decimal,9),
					new SqlParameter("@lr_zys", SqlDbType.Decimal,9),
					new SqlParameter("@lr_fcs", SqlDbType.Decimal,9),
					new SqlParameter("@lr_tdsys", SqlDbType.Decimal,9),
					new SqlParameter("@lr_tdzzs", SqlDbType.Decimal,9),
					new SqlParameter("@lr_yhs", SqlDbType.Decimal,9),
					new SqlParameter("@lr_ccs", SqlDbType.Decimal,9),
					new SqlParameter("@lr_qysds", SqlDbType.Decimal,9),
					new SqlParameter("@lr_grsds", SqlDbType.Decimal,9),
					new SqlParameter("@lr_jyffj", SqlDbType.Decimal,9),
					new SqlParameter("@lr_dfjyffj", SqlDbType.Decimal,9),
					new SqlParameter("@lr_sljszxzj", SqlDbType.Decimal,9),
					new SqlParameter("@lr_whsyjsf", SqlDbType.Decimal,9),
					new SqlParameter("@lr_jbylbx", SqlDbType.Decimal,9),
					new SqlParameter("@lr_gsbx", SqlDbType.Decimal,9),
					new SqlParameter("@ls_ngsybx", SqlDbType.Decimal,9),
					new SqlParameter("@ls_jbylbx", SqlDbType.Decimal,9),
					new SqlParameter("@ls_sybx", SqlDbType.Decimal,9),
					new SqlParameter("@ls_cjrbzj", SqlDbType.Decimal,9),
					new SqlParameter("@lr_id", SqlDbType.Int,4)};
			parameters[0].Value = model.lr_code;
			parameters[1].Value = model.lr_ny;
			parameters[2].Value = model.lr_yys;
			parameters[3].Value = model.lr_cjs;
			parameters[4].Value = model.lr_zys;
			parameters[5].Value = model.lr_fcs;
			parameters[6].Value = model.lr_tdsys;
			parameters[7].Value = model.lr_tdzzs;
			parameters[8].Value = model.lr_yhs;
			parameters[9].Value = model.lr_ccs;
			parameters[10].Value = model.lr_qysds;
			parameters[11].Value = model.lr_grsds;
			parameters[12].Value = model.lr_jyffj;
			parameters[13].Value = model.lr_dfjyffj;
			parameters[14].Value = model.lr_sljszxzj;
			parameters[15].Value = model.lr_whsyjsf;
			parameters[16].Value = model.lr_jbylbx;
			parameters[17].Value = model.lr_gsbx;
			parameters[18].Value = model.ls_ngsybx;
			parameters[19].Value = model.ls_jbylbx;
			parameters[20].Value = model.ls_sybx;
			parameters[21].Value = model.ls_cjrbzj;
			parameters[22].Value = model.lr_id;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int lr_id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from levy_record ");
			strSql.Append(" where lr_id=@lr_id");
			SqlParameter[] parameters = {
					new SqlParameter("@lr_id", SqlDbType.Int,4)
};
			parameters[0].Value = lr_id;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string lr_idlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from levy_record ");
			strSql.Append(" where lr_id in ("+lr_idlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Taxes.Model.levy_record GetModel(int lr_id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 lr_id,lr_code,lr_ny,lr_yys,lr_cjs,lr_zys,lr_fcs,lr_tdsys,lr_tdzzs,lr_yhs,lr_ccs,lr_qysds,lr_grsds,lr_jyffj,lr_dfjyffj,lr_sljszxzj,lr_whsyjsf,lr_jbylbx,lr_gsbx,ls_ngsybx,ls_jbylbx,ls_sybx,ls_cjrbzj from levy_record ");
			strSql.Append(" where lr_id=@lr_id");
			SqlParameter[] parameters = {
					new SqlParameter("@lr_id", SqlDbType.Int,4)
};
			parameters[0].Value = lr_id;

			Taxes.Model.levy_record model=new Taxes.Model.levy_record();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["lr_id"]!=null && ds.Tables[0].Rows[0]["lr_id"].ToString()!="")
				{
					model.lr_id=int.Parse(ds.Tables[0].Rows[0]["lr_id"].ToString());
				}
				if(ds.Tables[0].Rows[0]["lr_code"]!=null && ds.Tables[0].Rows[0]["lr_code"].ToString()!="")
				{
					model.lr_code=ds.Tables[0].Rows[0]["lr_code"].ToString();
				}
				if(ds.Tables[0].Rows[0]["lr_ny"]!=null && ds.Tables[0].Rows[0]["lr_ny"].ToString()!="")
				{
					model.lr_ny=ds.Tables[0].Rows[0]["lr_ny"].ToString();
				}
				if(ds.Tables[0].Rows[0]["lr_yys"]!=null && ds.Tables[0].Rows[0]["lr_yys"].ToString()!="")
				{
					model.lr_yys=decimal.Parse(ds.Tables[0].Rows[0]["lr_yys"].ToString());
				}
				if(ds.Tables[0].Rows[0]["lr_cjs"]!=null && ds.Tables[0].Rows[0]["lr_cjs"].ToString()!="")
				{
					model.lr_cjs=decimal.Parse(ds.Tables[0].Rows[0]["lr_cjs"].ToString());
				}
				if(ds.Tables[0].Rows[0]["lr_zys"]!=null && ds.Tables[0].Rows[0]["lr_zys"].ToString()!="")
				{
					model.lr_zys=decimal.Parse(ds.Tables[0].Rows[0]["lr_zys"].ToString());
				}
				if(ds.Tables[0].Rows[0]["lr_fcs"]!=null && ds.Tables[0].Rows[0]["lr_fcs"].ToString()!="")
				{
					model.lr_fcs=decimal.Parse(ds.Tables[0].Rows[0]["lr_fcs"].ToString());
				}
				if(ds.Tables[0].Rows[0]["lr_tdsys"]!=null && ds.Tables[0].Rows[0]["lr_tdsys"].ToString()!="")
				{
					model.lr_tdsys=decimal.Parse(ds.Tables[0].Rows[0]["lr_tdsys"].ToString());
				}
				if(ds.Tables[0].Rows[0]["lr_tdzzs"]!=null && ds.Tables[0].Rows[0]["lr_tdzzs"].ToString()!="")
				{
					model.lr_tdzzs=decimal.Parse(ds.Tables[0].Rows[0]["lr_tdzzs"].ToString());
				}
				if(ds.Tables[0].Rows[0]["lr_yhs"]!=null && ds.Tables[0].Rows[0]["lr_yhs"].ToString()!="")
				{
					model.lr_yhs=decimal.Parse(ds.Tables[0].Rows[0]["lr_yhs"].ToString());
				}
				if(ds.Tables[0].Rows[0]["lr_ccs"]!=null && ds.Tables[0].Rows[0]["lr_ccs"].ToString()!="")
				{
					model.lr_ccs=decimal.Parse(ds.Tables[0].Rows[0]["lr_ccs"].ToString());
				}
				if(ds.Tables[0].Rows[0]["lr_qysds"]!=null && ds.Tables[0].Rows[0]["lr_qysds"].ToString()!="")
				{
					model.lr_qysds=decimal.Parse(ds.Tables[0].Rows[0]["lr_qysds"].ToString());
				}
				if(ds.Tables[0].Rows[0]["lr_grsds"]!=null && ds.Tables[0].Rows[0]["lr_grsds"].ToString()!="")
				{
					model.lr_grsds=decimal.Parse(ds.Tables[0].Rows[0]["lr_grsds"].ToString());
				}
				if(ds.Tables[0].Rows[0]["lr_jyffj"]!=null && ds.Tables[0].Rows[0]["lr_jyffj"].ToString()!="")
				{
					model.lr_jyffj=decimal.Parse(ds.Tables[0].Rows[0]["lr_jyffj"].ToString());
				}
				if(ds.Tables[0].Rows[0]["lr_dfjyffj"]!=null && ds.Tables[0].Rows[0]["lr_dfjyffj"].ToString()!="")
				{
					model.lr_dfjyffj=decimal.Parse(ds.Tables[0].Rows[0]["lr_dfjyffj"].ToString());
				}
				if(ds.Tables[0].Rows[0]["lr_sljszxzj"]!=null && ds.Tables[0].Rows[0]["lr_sljszxzj"].ToString()!="")
				{
					model.lr_sljszxzj=decimal.Parse(ds.Tables[0].Rows[0]["lr_sljszxzj"].ToString());
				}
				if(ds.Tables[0].Rows[0]["lr_whsyjsf"]!=null && ds.Tables[0].Rows[0]["lr_whsyjsf"].ToString()!="")
				{
					model.lr_whsyjsf=decimal.Parse(ds.Tables[0].Rows[0]["lr_whsyjsf"].ToString());
				}
				if(ds.Tables[0].Rows[0]["lr_jbylbx"]!=null && ds.Tables[0].Rows[0]["lr_jbylbx"].ToString()!="")
				{
					model.lr_jbylbx=decimal.Parse(ds.Tables[0].Rows[0]["lr_jbylbx"].ToString());
				}
				if(ds.Tables[0].Rows[0]["lr_gsbx"]!=null && ds.Tables[0].Rows[0]["lr_gsbx"].ToString()!="")
				{
					model.lr_gsbx=decimal.Parse(ds.Tables[0].Rows[0]["lr_gsbx"].ToString());
				}
				if(ds.Tables[0].Rows[0]["ls_ngsybx"]!=null && ds.Tables[0].Rows[0]["ls_ngsybx"].ToString()!="")
				{
					model.ls_ngsybx=decimal.Parse(ds.Tables[0].Rows[0]["ls_ngsybx"].ToString());
				}
				if(ds.Tables[0].Rows[0]["ls_jbylbx"]!=null && ds.Tables[0].Rows[0]["ls_jbylbx"].ToString()!="")
				{
					model.ls_jbylbx=decimal.Parse(ds.Tables[0].Rows[0]["ls_jbylbx"].ToString());
				}
				if(ds.Tables[0].Rows[0]["ls_sybx"]!=null && ds.Tables[0].Rows[0]["ls_sybx"].ToString()!="")
				{
					model.ls_sybx=decimal.Parse(ds.Tables[0].Rows[0]["ls_sybx"].ToString());
				}
				if(ds.Tables[0].Rows[0]["ls_cjrbzj"]!=null && ds.Tables[0].Rows[0]["ls_cjrbzj"].ToString()!="")
				{
					model.ls_cjrbzj=decimal.Parse(ds.Tables[0].Rows[0]["ls_cjrbzj"].ToString());
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select lr_id,lr_code,lr_ny,lr_yys,lr_cjs,lr_zys,lr_fcs,lr_tdsys,lr_tdzzs,lr_yhs,lr_ccs,lr_qysds,lr_grsds,lr_jyffj,lr_dfjyffj,lr_sljszxzj,lr_whsyjsf,lr_jbylbx,lr_gsbx,ls_ngsybx,ls_jbylbx,ls_sybx,ls_cjrbzj ");
			strSql.Append(" FROM levy_record ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" lr_id,lr_code,lr_ny,lr_yys,lr_cjs,lr_zys,lr_fcs,lr_tdsys,lr_tdzzs,lr_yhs,lr_ccs,lr_qysds,lr_grsds,lr_jyffj,lr_dfjyffj,lr_sljszxzj,lr_whsyjsf,lr_jbylbx,lr_gsbx,ls_ngsybx,ls_jbylbx,ls_sybx,ls_cjrbzj ");
			strSql.Append(" FROM levy_record ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "levy_record";
			parameters[1].Value = "lr_id";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

